package com.yupi.usercenter.stream;

import com.yupi.usercenter.model.dto.MonitorWoAddDTO;
import com.yupi.usercenter.service.IMonitorWoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 问题件工单消息监听
 *
 * @author  chenchao
 * @version 1.0.0
 * @date 2020/9/24 11:13
 */
@Slf4j
@EnableBinding(InputInterface.class)
@Component
public class ProblemWorkOrderListener {

    @Resource
    private IMonitorWoService iMonitorWoService;

    /**
     * 工单消息监听
     * @param list 问题件工单数据列表
     */
    @StreamListener(value = InputInterface.CSS_PROBLEM_WORK_ORDER_INPUT)
    public void createProblemWorkOrder(@Payload List<MonitorWoAddDTO> list) {
        log.info("工单消息监听 接收到推送的消息,消息体为[{}]", list);
//        for (MonitorWoAddDTO monitorWoAddDTO : list) {
//            try {
//                if(ObjectUtils.isNotEmpty(monitorWoAddDTO.getProblemDescription()) && monitorWoAddDTO.getProblemDescription().length()>500){
//                    monitorWoAddDTO.setProblemDescription(monitorWoAddDTO.getProblemDescription().substring(0,500));
//                }
//                iMonitorWoService.add();
//            } catch (Exception e) {
//                log.error("ProblemWorkOrderListener createProblemWorkOrder异常：{}", e);
//            }
//        }

    }
}
